home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / binaries / Windows / jsdk / src / sun / servlet / isapi / ISAPIOutputStream.java < prev    next >
Encoding:
Java Source  |  1997-07-18  |  2.8 KB  |  108 lines

  1. /*
  2.  * @(#)ISAPIOutputStream.java    1.7 97/05/14
  3.  * 
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.0
  20.  */
  21.  
  22. package sun.servlet.isapi;
  23.  
  24. import java.io.OutputStream;
  25. import java.io.IOException;
  26. import sun.servlet.http.HttpOutputStream;
  27.  
  28. /**
  29.  * This class implements an output stream for writing ISAPI response data.
  30.  *
  31.  * @version    1.7, 05/14/97
  32.  * @author    David Connelly
  33.  * @author    Jongyoon Lee
  34.  */
  35. class ISAPIOutputStream extends HttpOutputStream {
  36.     /*
  37.      * The Extension Control Block (ECB) for this response.
  38.      */
  39.     private ISAPIConnection conn;
  40.  
  41.     /**
  42.      * Initializes the output stream with the ECB for this response.
  43.      */
  44.     public void init(ISAPIConnection conn) {
  45.     this.conn = conn;
  46.     next();
  47.     }
  48.  
  49.     /**
  50.      * Resets the output stream to an uninitialized state.
  51.      */
  52.     public void resets() {
  53.     super.resets();
  54.     this.conn = null;
  55.     }
  56.  
  57.     /**
  58.      * Flushes output stream bytes.
  59.      */
  60.     protected void flushBytes() throws IOException {
  61.     if (!committed) {
  62.         if (obs != null) {
  63.         obs.update(null, this);
  64.         }
  65.     }
  66.     committed = true;
  67.     if (count > 0) {
  68.         conn.writeClient(buf, 0, count);
  69.         count = 0;
  70.     }
  71.     }
  72.  
  73.     /**
  74.      * Checks the output stream for a pending IOException that needs to be
  75.      * thrown, a content length that has been exceeded, or observers that
  76.      * need to be notified.
  77.      * @param len the number of bytes about to be written
  78.      */
  79.     protected void check(int len) throws IOException {
  80.     // check for observers that need notifying.
  81.     if (limit < 0) {
  82.         if (total > 0) {
  83.               throw new InternalError();
  84.         }
  85.         // set the limit so that content length won't be exceeded
  86.         if (length != -1) {
  87.         limit = length;
  88.         } else {
  89.         limit = Integer.MAX_VALUE;
  90.         }
  91.     }
  92.     // check if content length exceeded
  93.     if (total + len > limit) {
  94.         limit = -1;
  95.         throw except = new IOException("write past end of stream");
  96.     }
  97.     }
  98.  
  99.     /*
  100.      * Writes to the underlying stream
  101.      */
  102.     protected void writeOut(byte[] buf, int offset, int len)
  103.     throws IOException
  104.     {
  105.     conn.writeClient(buf, offset, len);
  106.     }
  107. }
  108.